import axios from "../index";

const URLs = {
  getExamlist: "/examApi/exams/available",
  saveGrade: "/student/grades"
};

export const studentApi = {
  getExamList: async () => {
    return axios.get(URLs.getExamlist, {
      params: {
        studentId: sessionStorage.getItem('currentStudentId') || 1
      }
    });
  },
  saveGrades: async (gradeData: any, examId: number) => {
    try {
      const response = await axios.post(
        `${URLs.saveGrade}?examId=${examId}`,
        gradeData,
        {
          headers: {
            'Content-Type': 'application/json',
          },
        }
      );
      return response;
    } catch (error) {
      console.error('保存成绩失败:', error);
      throw error;
    }
  },
  // 保存错题
  saveWrongQuestions: (studentId: number, examId: number, wrongQuestions: any) => {
    return axios.post('/mistake/saveWrongQuestions', {
      studentId,
      examId,
      wrongQuestions
    });
  },
  getMistakes: (studentId: number) => {
    return axios.get(`/mistake/student/${studentId}/mistakes`);
  },

  // 删除错题
    deleteMistake(studentId: number, mistakeId: number) {
    return axios.delete(`/mistake/delete/${mistakeId}?studentId=${studentId}`);
  }
};
